let jygooglead = uni.requireNativePlugin("JY-GoogleAdMob");
const guanggao = {
	state: {
		indexNum:0,
		detailNum:0
	},
	mutations: {
		Add_ad_index:(state, num)=>{
			state.indexNum=num
			console.log('indexNum',state.indexNum);
			// #ifdef APP
			var jygooglead = uni.requireNativePlugin("JY-GoogleAdMob");
			jygooglead.jy_init();
			if(num%4 == 0){
				//展示
				jygooglead.jy_showInterstitialAd()
			}
			// #endif
			
		},
		Add_ad_detail:(state, num)=>{
			state.detailNum=num
			console.log('detailNum',state.detailNum);
			// #ifdef APP
			//每次都展示广告
			jygooglead.jy_init();
			//加载插屏广告
			console.log('加载插屏广告');
			jygooglead.jy_loadInterstitialAd({adId: getApp().globalData.insertAd},res=> {
				console.log('加载插屏广告',res);
				jygooglead.jy_showInterstitialAd()
			})
			// if(num%3 == 0){
			// 	//展示激励视频
			// 	jygooglead.jy_showRewardedAd()
			// }
			// #endif
			
		},
	},
	actions: { //异步操作mutation
		//加载插屏广告
		loading_Ad({commit,state}){
			// uni.clearStorageSync()
			// #ifdef APP
			jygooglead.jy_init();
			//加载插屏广告
			jygooglead.jy_loadInterstitialAd({adId: getApp().globalData.insertAd},res=> {
				console.log(res);
			})
			// #endif
		},
		//加载激励广告
		loading_Ad_Video({commit,state}){
			// #ifdef APP
			//加载激励广告
			jygooglead.jy_loadRewardedAd({
				adId: getApp().globalData.insertVideoAd,
				appId: 'ca-app-pub-7130333932129753~9197186401'
			}, res=> {});
			// #endif
		},
		add_ad_index({commit,state}) {
			let time = uni.$u.timeFormat(this.timestamp, 'yyyy-mm-dd');
			console.log(time);
			const num = uni.getStorageSync('index'+ time);
			if(num){
				let number = parseInt(num) + 1
				uni.setStorageSync('index'+time,number)
				commit('Add_ad_index',number)
			}else{
				uni.setStorageSync('index'+time,1)
				commit('Add_ad_index',1)
			}
		},
		add_ad_detail({commit,state}) {
			let time = uni.$u.timeFormat(this.timestamp, 'yyyy-mm-dd');
			const num = uni.getStorageSync('detail'+ time);
			if(num){
				let number = parseInt(num) + 1
				uni.setStorageSync('detail'+time,number)
				commit('Add_ad_detail',number)
			}else{
				uni.setStorageSync('detail'+time,1)
				commit('Add_ad_detail',1)
			}
		},
		
	}
}

export default guanggao
